package com.aishua.aishuawallet.diydialog;

import android.app.Dialog;
import android.app.DialogFragment;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.aishua.aishuawallet.R;


/**
 * Created by aishua on 2017/2/17.
 */

public class LoadingDialog extends DialogFragment {


    public static LoadingDialog newInstance(String tips,String msg) {

        LoadingDialog dialog = new LoadingDialog();
        Bundle args = new Bundle();
        args.putString("msg", msg);
        args.putString("tips", tips);
        dialog.setArguments(args);
        return dialog;
    }
    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {

        String msg = getArguments().getString("msg");
        String tips = getArguments().getString("tips");


        LayoutInflater inflaterDl = LayoutInflater.from(getActivity());
        RelativeLayout layout = (RelativeLayout) inflaterDl.inflate(R.layout.loding_dialog, null);

        //对话框
        final Dialog dialog = new Dialog(getActivity(),R.style.common_dialog_style);
        dialog.setContentView(layout);
        Window dialogWindow = dialog.getWindow();
        WindowManager.LayoutParams lp = dialogWindow.getAttributes();

        dialogWindow.setGravity(Gravity.CENTER);
        lp.width = (int) getResources().getDimension(R.dimen.dialog_exit_width);  // 宽度

        lp.height = (int) getResources().getDimension(R.dimen.dialog_load_height);  ; // 高度
        // 当Window的Attributes改变时系统会调用此函数,可以直接调用以应用上面对窗口参数的更改,也可以用setAttributes
        // dialog.onWindowAttributesChanged(lp);
        dialogWindow.setAttributes(lp);


        TextView tv_loading =  layout.findViewById(R.id.tv_loading);
        tv_loading.setText(msg);
        TextView tv_exit =  layout.findViewById(R.id.tv_exit);
        tv_exit.setText(tips);

        return dialog;

    }

}
